package com.google.code.stalkernet.node;

import java.util.Arrays;

/**
 * Abstract base class for implementations of {@link NodeID} interface.
 *
 * @author Mikhail Vladimirov
 */
public abstract class AbstractNodeID implements NodeID
{
    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode ()
    {
        return Arrays.hashCode (getBytes ());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals (Object obj)
    {
        if (obj instanceof NodeID)
            return Arrays.equals (getBytes (), ((NodeID)obj).getBytes ());
        else return false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString ()
    {
        return NodeUtils.formatNodeID (this);
    }
}
